package com.ruoyi.buss.report.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.report.mapper.ReportDkywzlJmjtsxqylMapper;
import com.ruoyi.buss.report.domain.ReportDkywzlJmjtsxqyl;
import com.ruoyi.buss.report.service.IReportDkywzlJmjtsxqylService;

/**
 * 居民家庭授信签约率-信贷类报1和2Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class ReportDkywzlJmjtsxqylServiceImpl implements IReportDkywzlJmjtsxqylService 
{
    @Autowired
    private ReportDkywzlJmjtsxqylMapper reportDkywzlJmjtsxqylMapper;

    /**
     * 查询居民家庭授信签约率-信贷类报1和2
     * 
     * @param sjrq 居民家庭授信签约率-信贷类报1和2ID
     * @return 居民家庭授信签约率-信贷类报1和2
     */
    @Override
    public ReportDkywzlJmjtsxqyl selectReportDkywzlJmjtsxqylById(String sjrq)
    {
        return reportDkywzlJmjtsxqylMapper.selectReportDkywzlJmjtsxqylById(sjrq);
    }

    /**
     * 查询居民家庭授信签约率-信贷类报1和2列表
     * 
     * @param reportDkywzlJmjtsxqyl 居民家庭授信签约率-信贷类报1和2
     * @return 居民家庭授信签约率-信贷类报1和2
     */
    @Override
    public List<ReportDkywzlJmjtsxqyl> selectReportDkywzlJmjtsxqylList(ReportDkywzlJmjtsxqyl reportDkywzlJmjtsxqyl)
    {
        return reportDkywzlJmjtsxqylMapper.selectReportDkywzlJmjtsxqylList(reportDkywzlJmjtsxqyl);
    }

    /**
     * 新增居民家庭授信签约率-信贷类报1和2
     * 
     * @param reportDkywzlJmjtsxqyl 居民家庭授信签约率-信贷类报1和2
     * @return 结果
     */
    @Override
    public int insertReportDkywzlJmjtsxqyl(ReportDkywzlJmjtsxqyl reportDkywzlJmjtsxqyl)
    {
        reportDkywzlJmjtsxqyl.setCreateTime(DateUtils.getNowDate());
        return reportDkywzlJmjtsxqylMapper.insertReportDkywzlJmjtsxqyl(reportDkywzlJmjtsxqyl);
    }

    /**
     * 修改居民家庭授信签约率-信贷类报1和2
     * 
     * @param reportDkywzlJmjtsxqyl 居民家庭授信签约率-信贷类报1和2
     * @return 结果
     */
    @Override
    public int updateReportDkywzlJmjtsxqyl(ReportDkywzlJmjtsxqyl reportDkywzlJmjtsxqyl)
    {
        return reportDkywzlJmjtsxqylMapper.updateReportDkywzlJmjtsxqyl(reportDkywzlJmjtsxqyl);
    }

    /**
     * 批量删除居民家庭授信签约率-信贷类报1和2
     * 
     * @param sjrqs 需要删除的居民家庭授信签约率-信贷类报1和2ID
     * @return 结果
     */
    @Override
    public int deleteReportDkywzlJmjtsxqylByIds(String[] sjrqs)
    {
        return reportDkywzlJmjtsxqylMapper.deleteReportDkywzlJmjtsxqylByIds(sjrqs);
    }

    /**
     * 删除居民家庭授信签约率-信贷类报1和2信息
     * 
     * @param sjrq 居民家庭授信签约率-信贷类报1和2ID
     * @return 结果
     */
    @Override
    public int deleteReportDkywzlJmjtsxqylById(String sjrq)
    {
        return reportDkywzlJmjtsxqylMapper.deleteReportDkywzlJmjtsxqylById(sjrq);
    }

    @Override
    public List<ReportDkywzlJmjtsxqyl> jtsxqyl(ReportDkywzlJmjtsxqyl reportDkywzlJmjtsxqyl, LoginUser userInfo) {
        List<ReportDkywzlJmjtsxqyl> doList = new ArrayList<ReportDkywzlJmjtsxqyl>();

        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDkywzlJmjtsxqyl.getSjrq())) {
            if ("9999".equals(reportDkywzlJmjtsxqyl.getSjrq())) {
                reportDkywzlJmjtsxqyl.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDkywzlJmjtsxqyl.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDkywzlJmjtsxqyl.setSjrqs(sjrqs);
        doList = reportDkywzlJmjtsxqylMapper.jtsxqyl(reportDkywzlJmjtsxqyl);

        return doList;
    }

    @Override
    public List<ReportDkywzlJmjtsxqyl> jtsxqylhz(ReportDkywzlJmjtsxqyl reportDkywzlJmjtsxqyl, LoginUser userInfo) {
        List<ReportDkywzlJmjtsxqyl> doListhz = new ArrayList<ReportDkywzlJmjtsxqyl>();


        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(reportDkywzlJmjtsxqyl.getSjrq())) {
            if ("9999".equals(reportDkywzlJmjtsxqyl.getSjrq())) {
                reportDkywzlJmjtsxqyl.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = reportDkywzlJmjtsxqyl.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }
        reportDkywzlJmjtsxqyl.setSjrqs(sjrqs);
//		PageHelper.orderBy("SJRQ ASC");
        doListhz = reportDkywzlJmjtsxqylMapper.jtsxqylhz(reportDkywzlJmjtsxqyl);
        return doListhz;
    }
}
